//Package services 商品数据处理Service层.
//该层主要用来数据获取后的额外处理,比如:缓存.
package services

import "ShopSupplierApi/models"

//ProductService Product服务层结构
type ProductService struct{}

//ProductServ 实例对象
var ProductServ *ProductService

func init() {
	ProductServ = &ProductService{}
}

//ProductList 货品列表
//param supplier_id uint64 供应商ID
//param search string 商品搜索关键词
//param status ProductStatusType 商品状态
//param p *Page 数据分页信息
func (*ProductService) ProductList(supplierID uint64, search string, status models.ProductStatusType, p *models.Page) []models.Product {
	return models.ProductList(supplierID, search, status, p)
}

//ProductInfo 货品信息
//param supplierID uint64	供应商ID
//param productID	uint64	货品ID
func (*ProductService) ProductInfo(supplierID uint64, productID uint64) *models.Product {
	return models.ProductInfo(supplierID, productID)
}

//SupplierSupplyProduct 供应商供应商品
//param supplierID uint64 供应商ID
//param productID uint64 货品ID
//param price float64 商品价格
//param productName string 自定义货品名称
//param productBn string 自定义货品BN
func (s *ProductService) SupplierSupplyProduct(supplierID uint64, productID uint64, price float64, productName string, productBn string) (bool, string) {
	if productName == "" || productBn == "" {
		p := s.ProductInfo(0, productID)
		if p == nil {
			return false, "商品不存在"
		}
		if productName == "" {
			productName = *p.Name
		}
		if productBn == "" {
			productBn = *p.Bn
		}
	}
	return models.SupplierSupplyProduct(supplierID, productID, price, productName, productBn)
}

//SupplierChangeStore 供应商修改库存
//param supplierID uint64 供应商ID
//param productID uint64 货品ID
//param singleprice float64 采购单价
//param nums int 数量
//param description string 备注
func (*ProductService) SupplierChangeStore(supplierID uint64, productID uint64, singleprice float64, nums int32, description string) (bool, string) {
	return models.SupplierChangeStore(supplierID, productID, singleprice, nums, description)
}

//SupplierMarketableChange 供应商货品上下架
//param supplierID uint64 供应商ID
//param productID uint64 货品ID
//param value bool 上架下架
func (*ProductService) SupplierMarketableChange(supplierID uint64, productID uint64, value bool) bool {
	return models.SupplierMarketableChange(supplierID, productID, value)
}

//SupplierUpdatePrice 供应商更改商品价格
//param supplierID uint64 供应商ID
//param productID uint64 货品ID
//param price float64 新价格
//param description string 备注
func (*ProductService) SupplierUpdatePrice(supplierID uint64, productID uint64, price float64, description string) bool {
	return models.SupplierUpdatePrice(supplierID, productID, price, description)
}

//ProductSaleLocal 货品销售区域统计
//param supplierID uint64 供应商ID
//param productID uint64 货品ID
//param localType int 地区标记[0=省,1=市,2=县]
//param regionID int 上一级地区ID
func (*ProductService) ProductSaleLocal(suppplierID uint64, productID uint64, localType int, regionID int) []map[string]interface{} {
	return models.ProductSaleLocal(suppplierID, productID, localType, regionID)
}
